#pragma once

#include <algorithm>
#include "IBitmapData.h"

namespace FTLib
{
	/// <summary>	Return value for CDataStore::AddOrSetValue. </summary>
	enum class DataStoreStatusCode
	{
		/// <summary>	The item was new and it was successfully added. </summary>
		OK_Added,

		/// <summary>	The item was already present, and it was successfully updated. </summary>
		OK_Updated,

		/// <summary>	The item was already present, but the stored length is less than what it was tried to update. </summary>
		LengthMismatch,

		/// <summary>	The item could not be added because it did not fit into the datastore. </summary>
		CapacityExceeded
	};

	/// <summary>	A very simplistic (but fast...) data store. It allows to store a couple of (untyped) items,
	/// 			the total size if limited by the template parameter (max. 255 bytes). The overhead per item is 3 bytes. 
	/// </summary>
	///
	/// <remarks>	This class is only meant to store just a few items. Also note that this class is not thread-safe. </remarks>
	///
	/// <typeparam name="tInitialSize">	The total size of the data store (255 bytes max!). </typeparam>
	template <uint8_t tInitialSize>
	class CDataStore
	{
	private:
		uint8_t builtinStore[tInitialSize];
		uint8_t sizeUsed;
	public:
		CDataStore() :sizeUsed(0)
		{
			memset(this->builtinStore, 0, tInitialSize);
		}

		bool	GetValue(uint16_t key, void* ptrData, uint8_t sizeData, uint8_t* ptrSizeRequired) const;

		ITinyDataStore::AddValueRetCode	AddOrSetValue(uint16_t key, void* ptrData, uint8_t sizeData);
	private:
		int GetOffsetForKey(uint16_t key) const;
	};

#include "datastore.hpp"

}